<?php
/**
 * 删除
 * Enter description here ...
 * @author nijn
 *
 */
class DeleteAction extends CAction {
	public $pk = 'id';
	public $returnUrl = '';
	public $msg = '操作成功';
	public $modelName = '';
	
	public function run() {
		$c = $this->controller;
		$modelName = empty($this->modelName) ? $c->modelName : $this->modelName;
		$model = new $modelName;
		$uid = Yii::app()->user->id;
		if (!empty($uid)) {
			$model = $model->findByAttributes(array(
				$this->pk = $_GET['id'],
				'uid' => Yii::app()->user->id
			));
			if ($model) {
				$model->delete();
				if (Yii::app()->request->isAjaxRequest) {
					Yii::app()->user->setFlash(FLASH::RESULT_SUCCESS, $this->msg);
					Yii::app()->end();
				}
				$c->redirect(
					empty($this->returnUrl) 
					? Yii::app()->request->urlReferrer : $this->returnUrl
				);
			}
		}
		$c->redirect(Yii::app()->request->urlReferrer);
	}
}

?>